示例#1
0
        public async Task <bool> UpdateObjectForRent(ObjectForRent objectForRent)
        {
            _context.Entry(_context.ObjectForRent.FirstOrDefault(c => c.ObjectForRentId == objectForRent.ObjectForRentId)).CurrentValues.SetValues(objectForRent);

            if (await _context.SaveChangesAsync() > 0)
            {
                return(true);
            }
            return(false);
        }
示例#2
0
        public async Task <bool> AddObjectForRent(ObjectForRent objectForRent)
        {
            await _context.AddAsync(objectForRent);

            if (await _context.SaveChangesAsync() > 0)
            {
                return(true);
            }
            return(false);
        }
示例#3
0
        public async Task <IActionResult> AddOrEdit(ObjectForRent objectForRent)
        {
            string Message;

            if (ModelState.IsValid)
            {
                //Insert
                if (objectForRent.ObjectForRentId == 0)
                {
                    await _objectForRentRepositorytory.AddObjectForRent(objectForRent);

                    Message = "Dodano obiekt";
                }
                //Update
                else
                {
                    bool value = await _objectForRentRepositorytory.UpdateObjectForRent(objectForRent);

                    if (value == false)
                    {
                        return(NotFound());
                    }
                    Message = "Edycja rezerwacji przebiegła pomyślnie";
                }

                var Objects = await _objectForRentRepositorytory.GetObjectForRents();

                return(Json(new { html = Helper.RenderRazorViewToString(this, "ObjectForRentList", Objects), message = Message, style = "success" }));
            }
            else
            {
                Message = "Wprowadz poprawne dane";
                var Objects = await _objectForRentRepositorytory.GetObjectForRents();

                return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "ObjectForRentList", Objects), message = Message, style = "error" }));
            }
        }