Exam - 25 October 2020 - GIT
Здравейте колеги,
може ли някой да помогне с решението на този изпит:
25 October 2020 - GIT.
Благодаря ви!
Ива
P.S. Каква може да е причината User-а винаги да е logged-out?
Здравейте колеги,
може ли някой да помогне с решението на този изпит:
25 October 2020 - GIT.
Благодаря ви!
Ива
P.S. Каква може да е причината User-а винаги да е logged-out?
Някой може ли да качи функционалността за CommitsControllera и съответно сървисите и вютата към него? Благодаря!
С голямо закъснение, но чак сега успях да го довърша:
---Commits Controller------------------------------
using Git.Data;
using Git.Data.Models;
using Git.Services;
using Git.ViewModels;
using Git.ViewModels.Commits;
using Git.ViewModels.Users;
using SUS.HTTP;
using SUS.MvcFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Git.Controllers
{
public class CommitsController : Controller
{
private readonly ApplicationDbContext data;
private readonly IUsersService service;
public CommitsController(ApplicationDbContext data, IUsersService service)
{
this.data = data;
this.service = service;
}
public HttpResponse All()
{
if (this.IsUserSignedIn())
{
var commits = this.data.Commits
.Where(c => c.CreatorId == this.GetUserId())
.Select(c => new CommitListingModel
{
Id = c.Id,
Repository = c.Repository.Name,
Description = c.Description,
CreatedOn = c.CreatedOn.ToString(),
})
.ToList();
return this.View(commits);
}
return Error("You must sign in first.");
}
public HttpResponse Create(string id)
{
if (this.IsUserSignedIn())
{
var repo = this.data.Repositories
.Where(r => r.Id == id)
.Select(r => new CommitToRepoModel
{
Id = r.Id,
Name = r.Name
})
.FirstOrDefault();
if (repo == null)
{
return Error("Repository does not exist.");
}
return this.View(repo);
}
else
{
return Error("You must sign in first!");
}
}
[HttpPost]
public HttpResponse Create(CreateCommitsModel model)
{
if (!this.data.Repositories.Any(r => r.Id == model.Id))
{
return Error("Repository not found.");
}
if (model.Description.Length < 5)
{
return Error("Commit description have be at least 5 characters.");
}
var commit = new Commit
{
Description = model.Description,
CreatedOn = DateTime.UtcNow,
CreatorId = this.GetUserId(),
RepositoryId = model.Id
};
this.data.Commits.Add(commit);
this.data.SaveChanges();
return Redirect("/Repositories/All");
}
public HttpResponse Delete(string id)
{
var commit = this.data.Commits.Find(id);
if (commit == null || commit.CreatorId != this.GetUserId())
{
return Error("Commit not found.");
}
this.data.Commits.Remove(commit);
this.data.SaveChanges();
return Redirect("/Commits/All");
}
}
}
---Commits Views------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace Git.ViewModels.Commits
{
public class CommitListingModel
{
public string Id { get; set; }
public string Repository { get; set; }
public string Description { get; set; }
public string CreatedOn { get; set; }
}
}
---------
using System;
using System.Collections.Generic;
using System.Text;
namespace Git.ViewModels.Commits
{
public class CommitToRepoModel
{
public string Id { get; set; }
public string Name { get; set; }
}
}
-------
using System;
using System.Collections.Generic;
using System.Text;
namespace Git.ViewModels.Commits
{
public class CreateCommitsModel
{
public string Id { get; set; }
public string Description { get; set; }
}
}