Exemple #1
0
 //[ValidateAntiForgeryToken]
 public IActionResult Create(LibraryBranchCv libraryBranchCv)
 {
     if (ModelState.IsValid)
     {
         var duplicate = _context.LibraryBranches.Any(a => a.Name == libraryBranchCv.Name && a.Telephone == libraryBranchCv.Telephone);
         if (duplicate)
         {
             LibraryBranch libraryBranch = new LibraryBranch()
             {
                 Name           = libraryBranchCv.Name,
                 Address        = libraryBranchCv.Address,
                 Description    = libraryBranchCv.Description,
                 ImageUrl       = "/images/" + libraryBranchCv.ImageUrl,
                 Telephone      = libraryBranchCv.Telephone,
                 OpenDate       = libraryBranchCv.OpenDate,
                 BranchHourList = libraryBranchCv.BranchHourList
             };
             _context.Add(libraryBranch);
             _context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             TempData["ErrorMessage"] = "Item is already exist";
         }
     }
     return(View(libraryBranchCv));
 }
        public void Delete(int id)
        {
            LibraryBranch asset = _context.LibraryBranches.Where(s => s.Id == id).FirstOrDefault();

            _context.LibraryBranches.Remove(asset);
            _context.SaveChanges();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            LibraryBranch libraryBranch = db.LibraryBranches.Find(id);

            db.LibraryBranches.Remove(libraryBranch);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "LibraryBranchId,Name,Address,Phone,Hours")] LibraryBranch libraryBranch)
 {
     if (ModelState.IsValid)
     {
         db.Entry(libraryBranch).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(libraryBranch));
 }
Exemple #5
0
 public IActionResult CreateBranch(LibraryBranch newBranch, IFormFile ImageUrl)
 {
     newBranch.ImageUrl = "/images/branch/" + ImageUrl.FileName;
     _branch.Add(newBranch);
     if (ImageUrl != null)
     {
         var fileName = Path.Combine(he.WebRootPath + "/images/branch", Path.GetFileName(ImageUrl.FileName));
         ImageUrl.CopyTo(new FileStream(fileName, FileMode.Create));
     }
     return(RedirectToAction("ListBranch"));
 }
        private static LibraryBranch GetBranchById()
        {
            var librarybranch = new LibraryBranch
            {
                Id      = 678,
                Name    = "Momodu",
                Address = "3, Acour jucntion"
            };

            return(librarybranch);
        }
        public ActionResult Create([Bind(Include = "LibraryBranchId,Name,Address,Phone,Hours")] LibraryBranch libraryBranch)
        {
            if (ModelState.IsValid)
            {
                db.LibraryBranches.Add(libraryBranch);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(libraryBranch));
        }
        // GET: LibraryBranches/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LibraryBranch libraryBranch = db.LibraryBranches.Find(id);

            if (libraryBranch == null)
            {
                return(HttpNotFound());
            }
            return(View(libraryBranch));
        }
Exemple #9
0
        public IActionResult Add(BranchCreateModel newBranch)
        {
            LibraryBranch asset = new LibraryBranch();

            asset.Name        = newBranch.BranchName;
            asset.Address     = newBranch.Address;
            asset.Telephone   = newBranch.Telephone;
            asset.Description = newBranch.Description;
            asset.ImageUrl    = newBranch.ImageUrl;

            _branchService.Add(asset);

            return(View("./SuccessAdd"));
        }
        public void Get_Humanized_Branch_Hours()
        {
            var options = new DbContextOptionsBuilder <LibraryDbContext>()
                          .UseInMemoryDatabase("Gets_branch_hours")
                          .Options;

            using (var context = new LibraryDbContext(options))
            {
                var branch = new LibraryBranch {
                    Id = -190
                };

                var hours = new List <BranchHours>
                {
                    new BranchHours
                    {
                        Branch    = branch,
                        DayOfWeek = 1,
                        OpenTime  = 13,
                        CloseTime = 15
                    },

                    new BranchHours
                    {
                        Branch    = branch,
                        DayOfWeek = 2,
                        OpenTime  = 4,
                        CloseTime = 24
                    }
                };

                context.BranchHours.AddRange(hours);
                context.SaveChanges();
            }

            using (var context = new LibraryDbContext(options))
            {
                var sut      = new LibraryBranchService(context);
                var result   = sut.GetBranchHours(-190);
                var expected = new List <string>
                {
                    "Monday 13:00 to 15:00",
                    "Tuesday 04:00 to 00:00"
                };

                result.Should().BeEquivalentTo(expected);
            }
        }
Exemple #11
0
 public IActionResult NewBranch(NewBranchViewModel model)
 {
     if (ModelState.IsValid)
     {
         string UniqueFilePath = UploadFileMethod(model);
         var    newBranch      = new LibraryBranch
         {
             Id          = model.Id,
             Name        = model.Name,
             Address     = model.Address,
             Telephone   = model.Telephone,
             Description = model.Description,
             OpenDate    = model.OpenDate,
             ImageUrl    = UniqueFilePath
         };
         _branch.Add(newBranch);
         return(RedirectToAction("Detail", new { id = model.Id }));
     }
     return(View());
 }
Exemple #12
0
        public IActionResult Detail(int branchId)
        {
            LibraryBranch branch = _branches.GetLibraryBranch(branchId);

            BranchDetailModel model = new BranchDetailModel()
            {
                Id               = branch.Id,
                BranchName       = branch.Name,
                Address          = branch.Address,
                Description      = branch.Description,
                Telephone        = branch.Telephone,
                BranchOpenedDate = branch.OpenDate.ToString("yyyy-MM-dd"),
                ImageUrl         = branch.ImageUrl,
                IsOpen           = _branches.IsBranchOpen(branch.Id) ? "Open" : "Closed",
                HoursOpen        = _branches.GetBranchHours(branch.Id),
                NumberOfAssets   = _branches.GetAssetCount(branch.Id),
                NumberOfPatrons  = _branches.GetPatronCount(branch.Id),
                TotalAssetValue  = _branches.GetAssetsValue(branch.Id)
            };

            return(View(model));
        }
Exemple #13
0
        public bool Update(LibraryBranch branch)
        {
            var _branch = _context.LibraryBranches.Find(branch.Id);

            try
            {
                _branch.Name        = branch.Name;
                _branch.Address     = branch.Address;
                _branch.Telephone   = branch.Telephone;
                _branch.Description = branch.Description;
                _branch.OpenDate    = branch.OpenDate;
                //Update Author or Director

                _context.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
            //throw new NotImplementedException();
        }
 public void Update(LibraryBranch entity)
 {
     throw new NotImplementedException();
 }
 public void Add(LibraryBranch newBranch)
 {
     context.Add(newBranch);
 }
 public void Add(LibraryBranch newBranch)
 {
     this.db.LibraryBranches.Add(newBranch);
     this.db.SaveChanges();
 }
 public void AddLibraryBranch(LibraryBranch newLibraryBranch)
 {
     context.Add(newLibraryBranch);
     context.SaveChanges();
 }
Exemple #18
0
 public IActionResult AddBranch(LibraryBranch newBranch, IFormFile ImageUrl)
 {
     return(View());
 }
Exemple #19
0
 public async Task AddAsync(LibraryBranch newBranch)
 {
     _context.Add(newBranch);
     await _context.SaveChangesAsync();
 }
Exemple #20
0
 public void AddLibraryBranch(LibraryBranch libraryBranch)
 {
     _context.Add(libraryBranch);
 }
 public void Add(LibraryBranch newBranch)
 {
     _context.Add(newBranch);
     _context.SaveChanges();
 }
 public void Add(LibraryBranch model)
 {
     _context.Add(model);
     _context.SaveChanges();
 }