public void CreateItem(Order item)
        {
            if (item == null)
                throw new ArgumentNullException(nameof(item));

            _context.Entry(item).State = EntityState.Added;
            SaveChanges();
        }
        public IHttpActionResult GetContact(int id)
        {
            Contact contact = db.Contacts.Find(id);

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

            db.Entry(contact).Collection(c => c.Orders).Load();

            return(Ok(contact));
        }
Exemple #3
0
        public IActionResult LoadApp(IFormFile fileApp, string password)
        {
            try
            {
                if (fileApp.Length > 0)
                {
                    using (var reader = new StreamReader(fileApp.OpenReadStream()))
                    {
                        var parsedContentDisposition = ContentDispositionHeaderValue.Parse(fileApp.ContentDisposition);
                        var fileName = parsedContentDisposition.FileName;
                        if (Regex.Match(fileName, @"\.\w{3,4}$", RegexOptions.IgnoreCase).Value != ".apk")
                        {
                            return(StatusCode(404));
                        }
                        string path = Path.Combine(@"D:\order\app", fileName);

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            fileApp.CopyTo(stream);
                        }
                        LogApp fileLog = new LogApp {
                            id = 0, file = fileApp.FileName, path = path, period = DateTime.Now
                        };
                        db.Entry(fileLog).State = EntityState.Added;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(404));
            }
            return(Ok("Ok"));
        }
        public string SaveFromFile(string file)
        {
            string model;

            using (System.IO.StreamReader fileStr =
                       new System.IO.StreamReader(@"D:\order\log\" + file + ".txt"))
            {
                model = fileStr.ReadToEnd();
            }
            try
            {
                var log = new logsString {
                    id = 0, agent = "manual", content = model, date = DateTime.Now
                };
                db.Entry(log).State = EntityState.Added;
                db.SaveChanges();
                var logs = JsonConvert.DeserializeObject <log[]>(model);
                foreach (var item in logs.ToList())
                {
                    item.timeStampServer = DateTime.Now;
                    db.Entry(item).State = EntityState.Added;
                    db.SaveChanges();
                }
                var orders = JsonConvert.DeserializeObject <Order[]>(model);
                foreach (var a in orders.ToList())
                {
                    foreach (var c in db.Orders.Where(o => o.agent == a.agent && o.customer == a.customer && o.number == a.number).ToList())
                    {
                        db.Entry(c).State = EntityState.Deleted;
                        db.SaveChanges();
                    }
                }
                foreach (var item in orders)
                {
                    db.Entry(item).State = EntityState.Added;
                    db.SaveChanges();
                }
                return("Записано");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
 public ActionResult Edit([Bind(Include = "Id,CoffeeBeans,Sugar,Milk")] Orders order)
 {
     if (ModelState.IsValid)
     {
         ordersDb.Entry(order).State = EntityState.Modified;
         ordersDb.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(order));
 }
 public string Save(string model)
 {
     agent = db.agents.FirstOrDefault(s => s.name == db.MobileUsers.FirstOrDefault(a => a.AgentMobileId == User.Identity.Name).AgentName);
     using (System.IO.StreamWriter fileLog =
                new System.IO.StreamWriter(@"D:\order\log\" + agent.name + ".txt"))
     {
         fileLog.WriteLine("{0}", model);
     }
     try
     {
         var log = new logsString {
             id = 0, agent = agent.name, content = model, date = DateTime.Now
         };
         db.Entry(log).State = EntityState.Added;
         db.SaveChanges();
         var logs = JsonConvert.DeserializeObject <log[]>(model);
         foreach (var item in logs.ToList())
         {
             item.timeStampServer = DateTime.Now;
             db.Entry(item).State = EntityState.Added;
             db.SaveChanges();
         }
         var orders = JsonConvert.DeserializeObject <Order[]>(model);
         if (!orders.Any())
         {
             return("Нет данных");
         }
         foreach (var a in orders.ToList())
         {
             foreach (var c in db.Orders.Where(o => o.agent == a.agent && o.customer == a.customer && o.number == a.number).ToList())
             {
                 db.Entry(c).State = EntityState.Deleted;
                 db.SaveChanges();
             }
         }
         foreach (var item in orders)
         {
             db.Entry(item).State = EntityState.Added;
             db.SaveChanges();
         }
         return("Записано");
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
 public ActionResult Edit([Bind(Include = "OrderId,ContactId,OrderDate,OrderDescription,OrderAmount")] Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ContactId = new SelectList(db.Contacts, "ContactId", "FirstName", order.ContactId);
     return(View(order));
 }
        public IActionResult Put([FromBody] Order order, int id)
        {
            if (order.Id != id)
            {
                return(BadRequest());
            }

            context.Entry(order).State = EntityState.Modified;
            context.SaveChanges();
            return(Ok());
        }
        public async Task <IActionResult> Update(Guid id, Order order)
        {
            if (id != order.Id)
            {
                return(BadRequest());
            }

            _context.Entry(order).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Ok(order));
        }
Exemple #10
0
        public async Task <IActionResult> Get(int id)
        {
            var order = await _context
                        .Orders
                        .FirstOrDefaultAsync(p => p.Id == id && !p.IsDeleted);

            _context.Entry(order)
            .Collection(b => b.OrderItems)     // .Reference(...)
            .Load();
            if (order == null)
            {
                throw new EntityNotFoundException();
            }
            return(Ok(_mapper.Map <OrderInfo>(order)));
        }
        public async Task <Order> UpdateOrderAsync(Order order)
        {
            if (order.Id != Guid.Empty && await CheckIfOrderExistInDBAsync(order.Id))
            {
                try
                {
                    _dbContext.Entry(order).State = EntityState.Modified;
                    await _dbContext.SaveChangesAsync();

                    return(order);
                }
                catch (SqlException)        // using Microsoft.Data.SqlClient;
                {
                    return(null);
                }
            }

            return(null);
        }
        /// <summary>
        /// Update order
        /// </summary>
        /// <param name="order"></param>
        /// <returns>bool</returns>
        public async Task <bool> UpdateOrderAsync(Order order)
        {
            // Does order contain a valid Id and exist in database?
            if (order.Id != Guid.Empty && await OrderExistAsync(order.Id))
            {
                try
                {
                    // Update
                    _context.Entry(order).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    return(true);
                }
                catch (SqlException)        // using Microsoft.Data.SqlClient;
                {
                    return(false);
                }
            }

            return(false);
        }
 public async Task UpdateAsync <T>(T resource)
 {
     _ordersDb.Entry(resource).State = EntityState.Modified;
     _ordersDb.Update(resource);
 }
Exemple #14
0
 public void UpdateOrder(Order order)
 {
     _context.Update(order);
     _context.Entry(order).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 }
Exemple #15
0
        public string Post()
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();

            try
            {
                string          reqType        = this.ReadQueryStringData("reqType");
                OrdersDbContext orderDbContext = new OrdersDbContext(connString);

                if (reqType != null && reqType == "AddToPreference")
                {
                    string preferenceType   = this.ReadQueryStringData("preferenceType");
                    string preferenceName   = null;
                    string preferenceIdType = null;
                    if (preferenceType.ToLower() == "lab")
                    {
                        preferenceName   = "Labtestpreferences";
                        preferenceIdType = "LabTestId";
                    }
                    else if (preferenceType.ToLower() == "imaging")
                    {
                        preferenceName   = "Imagingpreferences";
                        preferenceIdType = "ImagingItemId";
                    }
                    else if (preferenceType.ToLower() == "medication")
                    {
                        preferenceName   = "Medicationpreferences";
                        preferenceIdType = "MedicineId";
                    }

                    string ItemId = this.ReadQueryStringData("itemId");
                    //string clientValue = this.ReadPostData();

                    RbacUser currentUser = HttpContext.Session.Get <RbacUser>("currentuser");

                    EmployeePreferences employeePreference = (from pref in orderDbContext.EmployeePreferences
                                                              where pref.EmployeeId == currentUser.EmployeeId && pref.PreferenceName == preferenceName
                                                              select pref).FirstOrDefault();

                    if (employeePreference == null)
                    {
                        //this is used to convert string into xml
                        XmlDocument xdoc = JsonConvert.DeserializeXmlNode("{\"Row\":{" + preferenceIdType + ":" + ItemId + "}}", "root");
                        //this is add new perference
                        EmployeePreferences employeePref = new EmployeePreferences();

                        employeePref.PreferenceName  = preferenceName;
                        employeePref.PreferenceValue = xdoc.InnerXml;
                        employeePref.EmployeeId      = currentUser.EmployeeId;
                        employeePref.CreatedBy       = currentUser.EmployeeId;;
                        employeePref.CreatedOn       = DateTime.Now;
                        employeePref.IsActive        = true;
                        orderDbContext.EmployeePreferences.Add(employeePref);
                        orderDbContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = ItemId;
                    }
                    else
                    {
                        //creating object of XmlDocument
                        XmlDocument prefXmlDoc = new XmlDocument();
                        //loading the database PreferenceValue in object of XmlDocument(prefXmlDoc)
                        prefXmlDoc.LoadXml(employeePreference.PreferenceValue);
                        //creating xmlElement with tag Row
                        XmlElement Row = prefXmlDoc.CreateElement("Row");
                        //creating xmlElement with tag LabTestId/ImagingTypeId
                        XmlElement typeId = prefXmlDoc.CreateElement(preferenceIdType);
                        //provididng value to the element of LabTestId/ImagingTypeId
                        typeId.InnerText = ItemId;
                        //appending LabTestId/ImagingTypeId element ot Row element as child
                        Row.AppendChild(typeId);
                        //Appending the Row elemt to the root element of xml
                        prefXmlDoc.DocumentElement.AppendChild(Row);
                        //replacing the old value of employeePreference.PreferenceValue with new one
                        employeePreference.PreferenceValue = prefXmlDoc.InnerXml;
                        employeePreference.ModifiedBy      = currentUser.EmployeeId;
                        employeePreference.ModifiedOn      = DateTime.Now;


                        orderDbContext.Entry(employeePreference).State = EntityState.Modified;
                        orderDbContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = ItemId;
                    }
                }
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }
            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }
 public Task UpdateAsync(T item)
 {
     ordersDbContext.Entry(item).State = EntityState.Modified;
     return(ordersDbContext.SaveChangesAsync());
 }