コード例 #1
0
        public dynamic UpdateService([FromBody] Service Modell)
        {
            try
            {
                Service findService = db.Services.Where(zz => zz.ServiceID == Modell.ServiceID).FirstOrDefault();
                findService.Name        = Modell.Name;
                findService.Description = Modell.Description;
                findService.Duration    = Modell.Duration;
                findService.TypeID      = Modell.TypeID;
                db.SaveChanges();

                foreach (ServicePrice Items in Modell.ServicePrices)
                {
                    ServicePrice findPrice = db.ServicePrices.Where(zz => zz.PriceID == Items.PriceID && zz.Price == Items.Price).FirstOrDefault();
                    if (findPrice == null)
                    {
                        ServicePrice PriceObject = new ServicePrice();
                        PriceObject.ServiceID = findService.ServiceID;
                        PriceObject.OptionID  = Items.OptionID;
                        PriceObject.Price     = Items.Price;
                        PriceObject.Date      = DateTime.Now;
                        db.ServicePrices.Add(PriceObject);
                        db.SaveChanges();
                    }
                }
                return("success");
            }
            catch (Exception err)
            {
                return(err.Message);
            }
        }
コード例 #2
0
        private void LoopPrices(ListView lvCurrencies, long?countryId = null, long?countryRegionId = null)
        {
            foreach (ListViewDataItem item in lvCurrencies.Items)
            {
                long    currencyId     = long.Parse((item.FindControl <HiddenField>("HdfId")).Value);
                long?   servicePriceId = item.FindControl <HiddenField>("HdfPriceId").Value.TryParse <long>();
                decimal?price          = (item.FindControl <TextBox>("TxtPrice")).Text.ParseToDecimal();

                if (servicePriceId != null)
                {
                    if (price != null)
                    {
                        ServicePrice servicePrice = shippingMethod.OriginalPrices.SingleOrDefault(p => p.Id == servicePriceId.Value);
                        servicePrice.Value = price.Value;
                    }
                    else
                    {
                        shippingMethod.OriginalPrices.RemoveAll(p => p.Id == servicePriceId.Value);
                    }
                }
                else
                {
                    if (price != null)
                    {
                        shippingMethod.OriginalPrices.Add(countryId == null ? new ServicePrice(currencyId, price.Value) : new ServicePrice(currencyId, price.Value, countryId.Value, countryRegionId));
                    }
                }
            }
        }
コード例 #3
0
        public async Task <Response> Insert([FromForm] ServicePrice model)
        {
            Response _objResponse = new Response();

            try
            {
                if (ModelState.IsValid)
                {
                    model.CreatedDate = DateTime.Now;
                    model.UpdatedDate = DateTime.Now;
                    _context.Add(model);
                    await _context.SaveChangesAsync();

                    _objResponse.Status = "Success";
                    _objResponse.Data   = null;
                }
                else
                {
                    _objResponse.Status = "Validation Error";
                    _objResponse.Data   = null;
                }
            }
            catch (Exception ex)
            {
                _objResponse.Data   = null;
                _objResponse.Status = ex.ToString();
                Console.WriteLine("\nMessage ---\n{0}", ex.ToString());
                Console.WriteLine("\nStackTrace ---\n{0}", ex.StackTrace);
            }
            return(_objResponse);
        }
コード例 #4
0
        public async Task <Response> Update(int id, [FromForm] ServicePrice model)
        {
            Response _objResponse = new Response();

            try
            {
                if (id != model.ServicePriceId)
                {
                    _objResponse.Status = "No record found";
                    _objResponse.Data   = null;
                }
                else
                {
                    model.UpdatedDate = DateTime.Now;
                    _context.Entry(model).Property(x => x.CreatedDate).IsModified = false;
                    _context.Entry(model).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    _objResponse.Status = "Success";
                    _objResponse.Data   = null;
                }
            }
            catch (Exception ex)
            {
                _objResponse.Data   = null;
                _objResponse.Status = ex.ToString();
                Console.WriteLine("\nMessage ---\n{0}", ex.ToString());
                Console.WriteLine("\nStackTrace ---\n{0}", ex.StackTrace);
            }
            return(_objResponse);
        }
コード例 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("IdServicePrice,ServicePriceDescr,CtAmountHour,ClAmountHour,ServicePriceStatus")] ServicePrice servicePrice)
        {
            if (id != servicePrice.IdServicePrice)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(servicePrice);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ServicePriceExists(servicePrice.IdServicePrice))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(servicePrice));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("IdServicePrice,ServicePriceDescr,CtAmountHour,ClAmountHour,ServicePriceStatus")] ServicePrice servicePrice)
        {
            if (ModelState.IsValid)
            {
                _context.Add(servicePrice);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(servicePrice));
        }
コード例 #7
0
        protected void LvDefaultCurrencies_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            Currency currency = (Currency)(e.Item as ListViewDataItem).DataItem;

            ServicePrice servicePrice = shippingMethod.OriginalPrices.Get(currency.Id);

            if (servicePrice != null)
            {
                e.Item.FindControl <HiddenField>("HdfPriceId").Value = servicePrice.Id.ToString();
                e.Item.FindControl <TextBox>("TxtPrice").Text        = servicePrice.Value.ToString("0.####");
            }
        }
コード例 #8
0
        protected void LvCurrencies_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            Currency currency = (Currency)(e.Item as ListViewDataItem).DataItem;

            //Write Currency name
            e.Item.FindControl <Label>("LblCurrencyName").Text = currency.Name;

            ServicePrice servicePrice = shippingMethod.OriginalPrices.Get(currency.Id, currentCountryId, currentCountryRegionId);

            if (servicePrice != null)
            {
                e.Item.FindControl <HiddenField>("HdfPriceId").Value = servicePrice.Id.ToString();
                e.Item.FindControl <TextBox>("TxtPrice").Text        = servicePrice.Value.ToString("0.####");
            }
        }
コード例 #9
0
 //method used to save the service price
 public void SaveServicePrice(ServicePrice servicePrice)
 {
     if (servicePrice.IdServicePrice == 0)
     {
         context.ServicePrice.Add(servicePrice);
     }
     else
     {
         ServicePrice dbEntry = context.ServicePrice.
                                FirstOrDefault(s => s.IdServicePrice == servicePrice.IdServicePrice);
         if (dbEntry != null)
         {
             dbEntry.ServicePriceDescr  = servicePrice.ServicePriceDescr;
             dbEntry.CtAmountHour       = servicePrice.CtAmountHour;
             dbEntry.ClAmountHour       = servicePrice.ClAmountHour;
             dbEntry.ServicePriceStatus = servicePrice.ServicePriceStatus;
         }
     }
     context.SaveChanges();
 }
コード例 #10
0
        private void dgvAddServiceChange_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                //Delete Column
                if (dgvAddServiceChange.Columns[e.ColumnIndex] == clmbtnDelete)
                {
                    btnUpdate.Visible = true;
                    btnUpdate.Visible = false;

                    ServiceID = Convert.ToInt32(dgvAddServiceChange.Rows[e.RowIndex].Cells[clmServiceID.Name].Value);

                    DialogResult dr = MessageBox.Show("Are you sure want to Delete in this Service ?", "CONFIRMATION", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);

                    if (dr == DialogResult.Yes)
                    {
                        Execute        objExecute = new Execute();
                        SqlParameter[] param      = new SqlParameter[]
                        {
                            Execute.AddParameter("@intServiceID", ServiceID),
                        };
                        int NoOfRowsEffected = objExecute.Executes("spDeleteService", param, CommandType.StoredProcedure);

                        if (NoOfRowsEffected < 0)
                        {
                            MessageBox.Show("Successfully DELETE !");
                            GridLoad();
                            btnSave.Visible   = true;
                            btnUpdate.Visible = false;
                        }
                        else
                        {
                            MessageBox.Show("Item DELETE Process Error !");
                        }
                    }
                }

                //edit column

                // btnSave.Visible = false;
                // btnUpdate.Visible = true;

                if (dgvAddServiceChange.Columns[e.ColumnIndex] == clmbtnEdit)
                {
                    decimal ServicePrice;


                    ServiceID = Convert.ToInt32(dgvAddServiceChange.Rows[e.RowIndex].Cells[clmServiceID.Name].Value);

                    {
                        Execute        objExecute = new Execute();
                        string         Query      = "[dbo].[spGetServiceToEdit]";
                        SqlParameter[] paramt     = new SqlParameter[]
                        {
                            Execute.AddParameter("@intServiceID", ServiceID)
                        };
                        DataSet ds = (DataSet)objExecute.Executes(Query, ReturnType.DataSet, paramt, CommandType.StoredProcedure);

                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            txtServiceDec.Text = ds.Tables[0].Rows[0]["vcServiceName"].ToString();
                            ServicePrice       = Convert.ToDecimal(ds.Tables[0].Rows[0]["decPrice"].ToString());
                            txtPrice.Text      = ServicePrice.ToString();
                        }

                        btnSave.Visible   = false;
                        btnUpdate.Visible = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Data Deleting Error");
                Logger.LoggError(ex, "dgvAddServiceChange_CellClick");
            }
        }
コード例 #11
0
        private dynamic SaveService(Service Modell)
        {
            dynamic toReturn = new ExpandoObject();

            try
            {
                db.Configuration.ProxyCreationEnabled = false;
                //first Save the service information
                Service myObject = new Service();
                myObject.Name        = Modell.Name;
                myObject.Description = Modell.Description;
                myObject.Duration    = Modell.Duration;
                myObject.TypeID      = Modell.TypeID;
                db.Services.Add(myObject);
                db.SaveChanges();

                //retrieve the service ID from the info that were just saved
                int ServiceID = db.Services.Where(zz => zz.Name == Modell.Name).Select(zz => zz.ServiceID).FirstOrDefault();

                if (Modell.ServicePrices != null)
                {
                    foreach (ServicePrice Items in Modell.ServicePrices)
                    {
                        //Save the Service price object
                        ServicePrice PriceObject = new ServicePrice();
                        PriceObject.ServiceID = ServiceID;
                        //PriceObject.OptionID = Items.OptionID;
                        PriceObject.Price = Items.Price;
                        PriceObject.Date  = DateTime.Now;
                        db.ServicePrices.Add(PriceObject);

                        db.SaveChanges();
                    }
                }

                if (Modell.ServiceTypeOptions != null)
                {
                    foreach (ServiceTypeOption Items in Modell.ServiceTypeOptions)
                    {
                        //saves the OptionID and ServiceID into bride entity
                        ServiceTypeOption newObject = new ServiceTypeOption();
                        newObject.ServiceID = ServiceID;
                        int OptionID = (int)Items.OptionID;
                        newObject.OptionID = OptionID;
                        db.ServiceTypeOptions.Add(newObject);
                        db.SaveChanges();

                        foreach (ServicePrice PriceItem in Items.ServicePrices)
                        {
                            ServicePrice PriceObject = new ServicePrice();
                            PriceObject.ServiceID = ServiceID;
                            PriceObject.OptionID  = OptionID;
                            PriceObject.Price     = PriceItem.Price;
                            PriceObject.Date      = DateTime.Now;
                            db.ServicePrices.Add(PriceObject);

                            db.SaveChanges();
                        }
                    }
                }

                toReturn.Message   = "success";
                toReturn.ServiceID = ServiceID;
                return(toReturn);
            }
            catch (Exception err)
            {
                return(err.Message);
            }
        }