Beispiel #1
0
        public fullBackupInfo FindBackupByIdBackup(int idBackup)
        {
            backup backup = new backup();

            backup = this.context.Backups.Find(idBackup);

            fullBackupInfo fbi = new fullBackupInfo(backup);

            return(fbi);
        }
        public fullBackupAndClientsInfo FindById(int id)
        {
            backup backup = new backup();

            backup = this.context.Backups.Find(id);

            fullBackupAndClientsInfo fbi = new fullBackupAndClientsInfo(backup);

            return(fbi);
        }
        //    [ResponseType(typeof(void))]

        public async Task <IActionResult> Putdetails(string id, [FromBody] details details)
        {
            //  details details = await db.Details.FindAsync(id);


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));                                                         //update details
            }

            if (id != details.vehicleNo)
            {
                return(BadRequest("Id is not valid"));
            }

            if (details.outTime < details.inTime)
            {
                return(BadRequest("out time cannot be smaller than in time"));
            }

            string   v;
            DateTime date;
            double   outTime;

            if (details.outTime != null)
            {
                details.cost = (details.outTime - details.inTime) * 3;
                parkingslot p = db.Parkingslots.Where(x => x.sl == details.Slot).FirstOrDefault();
                p.availability = Availability.Available;
                backup b = new backup();

                b.name          = details.name;
                b.contactNumber = details.contactNumber;
                b.vehicleNo     = details.vehicleNo;
                b.date          = details.date;
                // b.floor = details.serialno.floor;
                // b.slot = details.serialno.slot;
                // b.section = details.serialno.section;
                b.slot    = Convert.ToInt32(details.Slot);
                b.inTime  = details.inTime;
                b.outTime = Convert.ToDouble(details.outTime);
                b.cost    = Convert.ToDouble(details.cost);
                db.Backups.Add(b);
                v       = b.vehicleNo;
                date    = b.date.Date;
                outTime = b.outTime;

                db.Entry(details).State = EntityState.Modified;



                try
                {
                    await db.SaveChangesAsync();

                    db.Details.Remove(details);
                    await db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!detailsExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }


                return(CreatedAtAction("GetBackups", new { controller = "backups", id = v }, details));
            }
            else
            {
                db.Entry(details).State = EntityState.Modified;
                try
                {
                    await db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!detailsExists(id))
                    {
                        return(NotFound("Id is not valid"));
                    }
                    else
                    {
                        throw;
                    }
                }

                return(CreatedAtAction("Getdetails", new { controller = "details", id = id }, details));
            }
        }