コード例 #1
0
        public async Task <IActionResult> EmailInvoiceAsync(string Id)
        {
            ApplicationUser Usr        = _userManager.GetUserAsync(User).Result;
            var             unitOfWork = new UnitofWork(_applicationDBcontext, Usr, loggerfactory);
            var             result     = unitOfWork.Invoices.GetInvoicebyId(Id);
            var             model      = _mapper.Map <tblInvoice, InvoiceVewModel>(result);

            model.OrganisationEmail = Usr.OrganisationEmail;
            model.OrganisationName  = Usr.OrganisationName;
            model.Person            = Usr.Person;
            model.AddressCode       = Usr.AddressCode;
            model.AddressL1         = Usr.AddressL1;
            model.AddressL2         = Usr.AddressL2;
            model.AddressL3         = Usr.AddressL3;
            model.AddressL4         = Usr.AddressL4;
            model.AddressL5         = Usr.AddressL5;
            model.InvoiceUrl        = Url.Action("ViewInvoice", "Invoice", new { Id = model.Id }, Request.Scheme);
            var HTMLstring = await this.RenderViewAsync <InvoiceVewModel>("InvoiceEmail", model, true);

            //StreamWriter sw = new StreamWriter("C:\\Users\\Carl\\Emailtest.html");
            //sw.Write(HTMLstring);
            //sw.Close();
            var PostEmail = new SendGridClient(_appSettings.SendGridKey);
            var From      = new EmailAddress(Usr.Email, Usr.UserName);
            var Replyto   = new EmailAddress(Usr.OrganisationEmail, Usr.OrganisationName);
            var To        = new EmailAddress(result.ToEmail, result.To);
            var Subject   = "Invoice :" + model.Code + " from :" + model.OrganisationName + " Date :" + model.Date;
            var Mail      = MailHelper.CreateSingleEmail(From, To, Subject, "", HTMLstring);
            var response  = await PostEmail.SendEmailAsync(Mail);

            result.Status = status.Sent;
            unitOfWork.Complete();
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //Tek class üzerinden bütün bütün repository yönetebiliyoruz
            UnitofWork unitofWork = new UnitofWork(new PersonelContext());

            unitofWork.DepartmentRepository.Add(new Department()
            {
                Name = "Pazarlama", IsActive = true, CreatedDate = DateTime.Now
            });

            unitofWork.DepartmentRepository.Add(new Department()
            {
                Name        = "Muhasebe",
                IsActive    = true,
                CreatedDate = DateTime.Now
            });

            unitofWork.DepartmentRepository.Add(new Department()
            {
                Name        = "Satis",
                IsActive    = true,
                CreatedDate = DateTime.Now
            });
            unitofWork.Complete();
            System.Console.WriteLine("oluþtu");
        }
コード例 #3
0
        public async Task <IActionResult> SaveInvoiceAsync(InvoiceVewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser Usr = await _userManager.GetUserAsync(User);

                var _unitOfWork = new UnitofWork(_applicationDBcontext, Usr, loggerfactory);
                var Exists      = _unitOfWork.Invoices.GetInvoicebyId(model.Id);

                if (Exists != null)
                {
                    // need to dig in to automapper on this lot more complex than it looks.
                    Exists.Code        = model.Code;
                    Exists.Date        = model.Date;
                    Exists.From        = model.From;
                    Exists.Note        = model.Note;
                    Exists.Price       = model.Price;
                    Exists.Tax         = model.Tax;
                    Exists.To          = model.To;
                    Exists.AttentionOf = model.AttentionOf;
                    Exists.ToEmail     = model.ToEmail;
                    Exists.Total       = model.Total;
                    // as the logic to update and add Items to the Invoice is complex decided to clear the list and replaces it with the
                    // one in the  model.  EF seems happy with this approach which it was not when modifying/adding Items to existing list.
                    Exists.Items.Clear();
                    for (int ct = 0; ct < model.Items.Count; ct++)
                    {
                        Exists.Items.Add(new tblInvoiceItems()
                        {
                            Item  = model.Items[ct].Item,
                            Price = model.Items[ct].Price,
                            Tax   = model.Items[ct].Tax,
                            Total = model.Items[ct].Total,
                        });
                    }
                }
                else
                {
                    var ToSave = _mapper.Map <InvoiceVewModel, tblInvoice>(model);
                    _unitOfWork.Invoices.AddRecord(ToSave);
                }
                var result = _unitOfWork.Complete();
                if (result.StartsWith("Failure "))
                {
                    ModelState.AddModelError("", result);
                    //ModelState.AddModelError("", "Invoice not saved, Error recieved on posting Invoice to Database. ");
                }
                else
                {
                    ModelState.AddModelError("", "Invoice saved");
                }
            }
            ViewData["Action"] = "Edit";
            return(View("Invoice", model));
        }
コード例 #4
0
        public HttpResponseMessage CreateProduct(ProductModel objPrpduct)
        {
            _UnitofWork.Product.Add(new DBEntities.Product()
            {
                ProductID   = objPrpduct.ProductID,
                ProductName = objPrpduct.ProductName,
                Price       = objPrpduct.Price
            });

            _UnitofWork.Complete();
            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
コード例 #5
0
        public IActionResult DeleteInvoice(string Id)
        {
            ApplicationUser Usr        = _userManager.GetUserAsync(User).Result;
            var             unitOfWork = new UnitofWork(_applicationDBcontext, Usr, loggerfactory);
            var             result     = unitOfWork.Invoices.GetInvoicebyId(Id);

            if (result.Status == status.Open)
            {
                unitOfWork.Invoices.RemoveRecord(result);
                var x = unitOfWork.Complete();
                return(RedirectToAction("IndexMsg", new { Message = "Invoice " + result.Code + " removed" }));
            }
            return(RedirectToAction("IndexMsg", new { Message = "Unable to remove Invoice " + result.Code + " Status is not Open. " }));
        }
コード例 #6
0
        //public string SavePO([FromQuery]string PurchaseOrder)
        public string SavePO([FromBody] JObject PurchaseOrder)
        {
            string     ToReturn = " processing PO  ";
            UnitofWork _uofw    = new UnitofWork(_context, _userManager.GetUserAsync(User).Result);
            var        result   = JsonConvert.DeserializeObject <PurchaseOrderJsonModel>(PurchaseOrder.ToString());
            //// get PO from database
            var PO = _uofw.PurchaseOrders.GetPurchaseOrderbyCode(result.Code);

            //// update it with the new details
            PODTO.UpdatePO(PO, result);
            //// send to the database
            _uofw.Complete();
            // report result.
            return(ToReturn);
        }
コード例 #7
0
 public async Task <IActionResult> Edit(Guid id, [Bind("Name,Contact,ContactEmail,ContactNo,Address")] OrganisationViewModel FromView)
 {
     if (ModelState.IsValid)
     {
         UnitofWork _uofw  = new UnitofWork(_context, _userManager.GetUserAsync(User).Result);
         var        result = _uofw.Organisations.GetOrganisationbyId(id);
         if (result == null)
         {
             return(NotFound());
         }
         OrgDTO.ToTableModel(result, FromView);
         _uofw.Complete();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(FromView));
 }