Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Boat_class_type,Created_At,Updated_At")] Boat_type boat_type)
        {
            if (id != boat_type.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    // To set the system time for record update
                    boat_type.Updated_At = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Trim());
                    _context.Update(boat_type);
                    _context.Entry(boat_type).Property(x => x.Created_At).IsModified = false; // To prevent the datetime property to be set as null on update operation
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Boat_typeExists(boat_type.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)).WithSuccess("Success", "Successfully Updated Boat Category Details"));
            }
            return(View(boat_type));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Boat_class_type,Created_At,Updated_At")] Boat_type boat_type, List <Sub_boat_type> sub_Boat_Types)
        {
            boat_type.Sub_Boat_Types = new List <Sub_boat_type>();
            if (ModelState.IsValid)
            {
                foreach (var sub_category in sub_Boat_Types)
                {
                    boat_type.Sub_Boat_Types.Add(new Sub_boat_type
                    {
                        Sub_boat_class_type = sub_category.Sub_boat_class_type,
                        Created_At          = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Trim())
                    });
                }
                // To pass the creation date on system time
                boat_type.Created_At = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Trim());
                _context.Add(boat_type);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)).WithSuccess("Success", "Successfully Inserted Boat Category Details"));
            }
            return(View(boat_type));
        }