public ClientPackage AddClient(ClientPackageAdd clientPackage, int createdbyId) { var toAdd = new ClientPackage { CreatedById = createdbyId, CreatedOn = DateTime.Now, Source = clientPackage.Source, OnlyFiles = clientPackage.OnlyFiles, PackageId = clientPackage.PackageId }; context.Add(toAdd); context.SaveChanges(); return(toAdd); }
public IActionResult AddClient(ClientPackageAdd package) { if (ModelState.IsValid) { var res = packageRepository.AddClient(package); if (res == null) { return(this.ValidateAndView(package)); } else { return(RedirectToAction(nameof(ToPackage), new { id = package.PackageId })); } } else { return(View(package)); } }
public ClientPackage AddClient(ClientPackageAdd client) { var validator = modelValidator.GetHelper <ClientPackageAdd>(); if (!context.Packages.Any(p => p.Id == client.PackageId && p.CreatedById == UserId)) { modelValidator.AddError(ClientPackageAdd.InvalidPackage); return(null); } else if (context.ClientPackages.Any(c => c.PackageId == client.PackageId && c.Source == client.Source)) { validator.AddError(c => c.Source, ClientPackageAdd.DuplicateSource); return(null); } else { return(AddClient(client, UserId)); } }