Ejemplo n.º 1
0
        public IHttpActionResult Put(int id, t_ListForPrint t_ListForPrint)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != t_ListForPrint.ListId)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!t_ListForPrintExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public IHttpActionResult Put(int id, [FromBody] EquipmentModelInput equipmentModelInput)
        {
#if DEBUG
            Debug.WriteLine("I'm in PUT");
#endif
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
#if DEBUG
            Debug.WriteLine("Put id=" + id.ToString());
#endif
            t_Equipment equipment = new t_Equipment();
            equipment.EquipmentId     = equipmentModelInput.EquipmentId;
            equipment.InventoryNumber = equipmentModelInput.InventoryNumber;
            equipment.MaterialAccount = equipmentModelInput.MaterialAccount;
            equipment.MOL             = equipmentModelInput.MOL;
            equipment.Name            = equipmentModelInput.Name;
            equipment.Price           = equipmentModelInput.Price;
            equipment.SerialNumber    = equipmentModelInput.SerialNumber;
            equipment.StartupDate     = Convert.ToDateTime(equipmentModelInput.StartupDate);
            db.Entry(equipment).State = EntityState.Modified;
            try
            {
                db.SaveChanges();
            }
            catch (DBConcurrencyException)
            {
#if DEBUG
                Debug.WriteLine("Catch is occuried!");
#endif
                return(NotFound());
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public IHttpActionResult Put(int id, int price)
        {
            t_CostOfRepair costOfRepair = db.t_CostOfRepair.Find(id);

            //CostOfRepairModel costOfRepair = db.t_CostOfRepair.Where(w => w.EquipmentId == id).Select(s => new CostOfRepairModel() { EquipmentId = s.EquipmentId, Price = s.Price }).FirstOrDefault();
            if (costOfRepair == null)
            {
#if DEBUG
                Debug.WriteLine("costOfRepair == null");
#endif
                costOfRepair             = new t_CostOfRepair();
                costOfRepair.EquipmentId = id;
                costOfRepair.Price       = price;
                db.t_CostOfRepair.Add(costOfRepair);
                db.SaveChanges();
            }
            else
            {
#if DEBUG
                Debug.WriteLine(String.Format("costOfRepair id={0},price={1}", id, price));
#endif
                costOfRepair.Price           = price;
                db.Entry(costOfRepair).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public IHttpActionResult Put(int id, DecommissionModel decommission)
        {
            t_Equipment equipment = db.t_Equipment.Find(id);

            if (equipment == null)
            {
                return(NotFound());
            }

            equipment.DateOfDecommission = decommission.DateOfDecommission;
            equipment.Decommission       = decommission.StateOfDecommission;
            db.Entry(equipment).State    = EntityState.Modified;
            try
            {
                db.SaveChanges();
            }
            catch (DBConcurrencyException)
            {
#if DEBUG
                Debug.WriteLine("Catch is occuried!");
#endif
                return(NotFound());
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 5
0
        //public IHttpActionResult Putt_TypeOfEquipment(int id, t_TypeOfEquipment t_TypeOfEquipment)
        public IQueryable <TypeofEquipmentModel> Putt_TypeOfEquipment(int id, TypeofEquipmentModel typeOfEquipmentModel)
        {
            if (!ModelState.IsValid)
            {
                //return BadRequest(ModelState);
                return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel()
                {
                    TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit
                }).AsQueryable());
            }

            t_TypeOfEquipment typeOfEquipment = db.t_TypeOfEquipment.Find(id);

            if (typeOfEquipment == null)
            {
                //return BadRequest();
                return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel()
                {
                    TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit
                }).AsQueryable());
            }

            typeOfEquipment.Name      = typeOfEquipmentModel.Name;
            typeOfEquipment.Warranty  = typeOfEquipmentModel.Warranty;
            typeOfEquipment.Limit     = typeOfEquipmentModel.Limit;
            typeOfEquipment.Effective = typeOfEquipmentModel.Effective;

            try
            {
                db.Entry(typeOfEquipment).State = EntityState.Modified;
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!t_TypeOfEquipmentExists(id))
                {
                    //return NotFound();
                    return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel()
                    {
                        TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit
                    }).AsQueryable());
                }
                else
                {
                    throw;
                }
            }
            return(db.t_TypeOfEquipment.Select(s => new TypeofEquipmentModel()
            {
                TypeId = s.TypeId, Name = s.Name, Effective = s.Effective, Warranty = s.Warranty, Limit = s.Limit
            }).AsQueryable());
            //return StatusCode(HttpStatusCode.NoContent);
        }
Ejemplo n.º 6
0
        public IQueryable <MalfunctionModel> Putt_Malfunction(int id, MalfunctionModel malfunctionModel)
        {
            if (!ModelState.IsValid)
            {
                //return BadRequest(ModelState);
                return(db.t_Malfunction.Select(s => new MalfunctionModel()
                {
                    FaultId = s.FaultId, Name = s.Name
                }));
            }

            t_Malfunction malfunction = db.t_Malfunction.Find(id);

            if (malfunction == null)
            {
                //return BadRequest();
                return(db.t_Malfunction.Select(s => new MalfunctionModel()
                {
                    FaultId = s.FaultId, Name = s.Name
                }));
            }

            malfunction.Name = malfunctionModel.Name;

            try
            {
                db.Entry(malfunction).State = EntityState.Modified;
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!t_MalfunctionExists(id))
                {
                    //return NotFound();
                    return(db.t_Malfunction.Select(s => new MalfunctionModel()
                    {
                        FaultId = s.FaultId, Name = s.Name
                    }));
                }
                else
                {
                    throw;
                }
            }

            //return StatusCode(HttpStatusCode.NoContent);
            return(db.t_Malfunction.Select(s => new MalfunctionModel()
            {
                FaultId = s.FaultId, Name = s.Name
            }));
        }
Ejemplo n.º 7
0
        public IHttpActionResult Put(int id, ExpertiseModel expertiseModel)
        {
#if DEBUG
            Debug.WriteLine(String.Format("Id={0},Staff={1}", expertiseModel.ExpertiseId.ToString(), expertiseModel.Staff));
#endif
            //ExpertiseModel expertise = db.t_Expertise.Where(w => w.EquipmentId == expertiseModel.EquipmentId).Select(s => new ExpertiseModel() {EquipmentId=s.EquipmentId,Staff=s.Staff,Reason=s.Reason,Conclusion=s.Conclusion }).FirstOrDefault();
            t_Expertise expertise = db.t_Expertise.Find(expertiseModel.ExpertiseId);
            //t_Expertise expertise = db.t_Expertise.Find(id);
            // if expertise is null then new act of expertise
            if (expertise == null)
            {
                expertise = new t_Expertise();
                //expertise.EquipmentId = id;
                expertise.Conclusion = expertiseModel.Conclusion;
                expertise.Reason     = expertiseModel.Reason;
                expertise.Staff      = expertiseModel.Staff; //user
                expertise.NumberExp  = expertiseModel.NumberExp;
#if DEBUG
                Debug.WriteLine("expertise == null expertiseModel.DateExp=" + expertiseModel.DateExp);
                //Debug.WriteLine(DateTimeOffset.Parse(expertiseModel.DateExp).ToString());
#endif
                expertise.DateExp = expertiseModel.DateExp;  //new DateTimeOffset()

                expertise.Staff2    = expertiseModel.Staff2; // customer
                expertise.RequestId = expertiseModel.RequestId;
#if DEBUG
                Debug.WriteLine("expertiseModel.IsServiceableEquipment=" + expertiseModel.IsServiceableEquipment.ToString());

                //Debug.WriteLine("^^^^^ FIO=" + user.FIO);
#endif
                expertise.IsServiceableEquipment = expertiseModel.IsServiceableEquipment;
                expertise.IsWarrantyRepair       = expertiseModel.IsWarrantyRepair;
                expertise.IsOrganizationRepair   = expertiseModel.IsOrganizationRepair;
                expertise.IsPartsSupply          = expertiseModel.IsPartsSupply;
                expertise.IsServiceable          = expertiseModel.IsServiceable;
                expertise.IsForWriteoff          = expertiseModel.IsForWriteoff;

                db.t_Expertise.Add(expertise);
                db.SaveChanges();
                db.Entry(expertise).GetDatabaseValues();
                t_Equipment equipment = db.t_Equipment.Find(id);
                if (equipment != null)
                {
                    equipment.t_Expertise.Add(expertise);
                    db.SaveChanges();
                }
#if DEBUG
                else
                {
                    Debug.WriteLine("equipment is null!");
                }
#endif


                // fill table t_UserExpertise
                var user = _userManager.FindByName(_userName);
                if (user != null)
                {
                    ExpertiseUser expertiseUser = new ExpertiseUser();
                    expertiseUser.AddUserToExpertise(expertise.ExpertiseId, user.UserID);
                }
#if DEBUG
                else
                {
                    Debug.WriteLine("user is null!");
                }
#endif

                try
                {
                    t_Message message = db.t_Message.FirstOrDefault();
                    if (message != null)
                    {
                        message.LastNumber      = expertiseModel.NumberExp;
                        db.Entry(message).State = EntityState.Modified;
                        db.SaveChanges();
                    }
#if DEBUG
                    else
                    {
                        Debug.WriteLine("message is null");
                    }
#endif
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                expertise.Conclusion             = expertiseModel.Conclusion;
                expertise.Reason                 = expertiseModel.Reason;
                expertise.Staff                  = expertiseModel.Staff;
                expertise.NumberExp              = expertiseModel.NumberExp;
                expertise.DateExp                = expertiseModel.DateExp;
                expertise.Staff2                 = expertiseModel.Staff2;
                expertise.RequestId              = expertiseModel.RequestId;
                expertise.IsServiceableEquipment = expertiseModel.IsServiceableEquipment;
                expertise.IsWarrantyRepair       = expertiseModel.IsWarrantyRepair;
                expertise.IsOrganizationRepair   = expertiseModel.IsOrganizationRepair;
                expertise.IsPartsSupply          = expertiseModel.IsPartsSupply;
                expertise.IsServiceable          = expertiseModel.IsServiceable;
                expertise.IsForWriteoff          = expertiseModel.IsForWriteoff;
                db.Entry(expertise).State        = EntityState.Modified;
                db.SaveChanges();
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 8
0
        public async Task <IHttpActionResult> PictureUploadPost(int id)
        {
#if DEBUG
            Debug.WriteLine("HttpPost Begin");
#endif
            var request = HttpContext.Current.Request;

            var validationRules = new FlowValidationRules();
            validationRules.AcceptedExtensions.AddRange(new List <string> {
                "jpeg", "jpg", "png", "bmp"
            });
            validationRules.MaxFileSize = 5000000;
            //validationRules.MaxFileSize = 50;
            //validationRules.MaxFileSizeMessage = "File's size is too big!";

            // try
            // {
            var status = _flowJs.PostChunk(request, _uploadFolder, validationRules);


            if (status.Status == PostChunkStatus.Done)
            {
                // file uploade is complete. Below is an example of further file handling
                var filePath = Path.Combine(_uploadFolder, status.FileName);
#if DEBUG
                Debug.WriteLine("filePath=" + filePath);
#endif
                var file = File.ReadAllBytes(filePath);
                //var picture = await _fileManager.UploadPictureToS3(User.Identity.GetUserId(), file, status.FileName);
                ModelState.AddModelError("file", "done");
                //ModelState.Add(KeyValuePair<"1122",ModelState.AddModelError("file", "done") >);
                //_fileManager = new BinaryFile(filePath);
                //byte[] bytesF = _fileManager.GetBinaryData();
                t_User user = _db.t_User.Where(w => w.UserID == id).FirstOrDefault();
                if (user != null)
                {
                    user.Sign             = File.ReadAllBytes(filePath);
                    _db.Entry(user).State = EntityState.Modified;
                    _db.SaveChanges();
                }
#if DEBUG
                else
                {
                    Debug.WriteLine("user==null");
                }
#endif
                //File.Delete(filePath);
                return(Ok());
                //return BadRequest(ModelState);
            }

            if (status.Status == PostChunkStatus.PartlyDone)
            {
                return(Ok());
            }

            status.ErrorMessages.ForEach(x => ModelState.AddModelError("file", x));
#if DEBUG
            foreach (var m in ModelState)
            {
                Debug.WriteLine("Key=" + m.Key + " value=" + m.Value.ToString());
            }
#endif
            return(BadRequest(ModelState));
            //}

            /*catch (Exception)
             * {
             *  ModelState.AddModelError("file", "exception");
             *  return BadRequest(ModelState);
             * }*/
        }