Пример #1
0
        public async Task <Document> ToTransferred(int id_interno)
        {
            using (var transaction = _dbContext.Database.CurrentTransaction ?? _dbContext.Database.BeginTransaction())
            {
                try
                {
                    var doc = await _dbContext.documento.FirstOrDefaultAsync(doci => doci.id_interno.Equals(id_interno));

                    doc.usuario_modificacion = "ByEmail";
                    doc.fecha_transferencia  = DateTime.Now;
                    doc.ultima_modificacion  = DateTime.Now;

                    if (doc == null || doc?.id_interno == 0)
                    {
                        return(null);
                    }
                    doc.id_tipo_documento_estado = 2;
                    doc.ultima_modificacion      = DateTime.Now;
                    await _dbContext.SaveChangesAsync();

                    transaction.Commit();
                    return(_mapper.Map <Document>(doc));
                }
                catch (Exception err)
                {
                    transaction.Rollback();
                    throw err;
                }
            }
        }
Пример #2
0
        public async Task <ActionResult <Contracts> > PostProducts(Contracts contracts)
        {
            //
            var oCustomerDoc = new Contracts();

            oCustomerDoc.CustomerName    = contracts.CustomerName;
            oCustomerDoc.CustomerAddress = contracts.CustomerAddress;
            oCustomerDoc.CustomerCountry = contracts.CustomerCountry;
            oCustomerDoc.CustomerDOB     = contracts.CustomerDOB;
            oCustomerDoc.CustomerGender  = contracts.CustomerGender;
            oCustomerDoc.SaleDate        = contracts.SaleDate;

            var coverplan = (from cover in _context.CoveragePlans where cover.EligibilityCountry == contracts.CustomerCountry select cover.CoveragePlanName).FirstOrDefault();

            oCustomerDoc.CoveragePlan = coverplan;

            int      age        = 0;
            DateTime dobcurrent = Convert.ToDateTime(contracts.CustomerDOB);

            age = DateTime.Now.Year - dobcurrent.Year;
            if (DateTime.Now.DayOfYear < dobcurrent.DayOfYear)
            {
                age = age - 1;
            }


            var netprice = (from rate in _context.RateCharts where rate.CoveragePlanName == coverplan && rate.CustomerGender == contracts.CustomerGender && rate.CustomerAge == Convert.ToString(age) select rate.NetPrice).FirstOrDefault();

            oCustomerDoc.NetPrice = netprice;
            _context.Contracts.Add(oCustomerDoc);
            await _context.SaveChangesAsync();

            return(oCustomerDoc);
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("AnimalId,AnimalName,AnimalDescription")] Animals animals)
        {
            if (ModelState.IsValid)
            {
                _context.Add(animals);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(animals));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("AboutZooID,Description,Date")] AboutZoo aboutZoo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aboutZoo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aboutZoo));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,CreateTime,LastUpdateTime")] CompetitionField competitionField)
        {
            if (ModelState.IsValid)
            {
                competitionField.CreateTime = DateTime.Now;
                _context.Add(competitionField);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(competitionField));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("StatusId,Title,CreateTime,LastUpdateTime,Editable")] Status status)
        {
            if (ModelState.IsValid)
            {
                status.CreateTime = DateTime.Now;
                _context.Add(status);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(status));
        }
        public async Task <IActionResult> Create([Bind("Id,FullName,PhoneNumber,PhoneNumberConfirmed,Email,EmailConfirmed,PhoneNumberVerifyCode,EmailVerifyCode,Password,Avatar,Role,AccessFailedCount,CreateTime,LastUpdateTime,IsDeleted,IsActive")] User user)
        {
            if (ModelState.IsValid)
            {
                user.Id = Guid.NewGuid();
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("AnnouncementId,AnnouncementTitle,AnnouncementText,Date")] Announcements announcements)
        {
            if (ModelState.IsValid)
            {
                announcements.Date = DateTime.Now;
                _context.Add(announcements);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(announcements));
        }
Пример #9
0
        public async Task <IActionResult> Create([Bind("Name,Quantity,Price,ProductTypeId,Id,CreatedOnUtc")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductTypeId"] = new SelectList(_context.Set <ProductType>(), "Id", "Name", product.ProductTypeId);
            return(View(product));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,CreateTime,LastUpdateTime,CompetitionBranchId,UserId")] CompetitionSubject competitionSubject)
        {
            if (ModelState.IsValid)
            {
                competitionSubject.CreateTime = DateTime.Now;
                _context.Add(competitionSubject);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CompetitionBranchId"] = new SelectList(_context.CompetitionBranchs, "Id", "Title", competitionSubject.CompetitionBranchId);
            return(View(competitionSubject));
        }
Пример #11
0
        public async Task <IActionResult> Create([Bind("Id,Subject,StatusId")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                ticket.Id = (Guid.NewGuid()).ToString();
                _context.Add(ticket);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StatusId"] = new SelectList(_context.Statues, "StatusId", "Title", ticket.StatusId);
            return(View(ticket));
        }
Пример #12
0
        public async Task <IActionResult> Create(IFormCollection formCollection, CreateParticipantViewModel participant)
        {
            Participant participantToAdd = new Participant();

            if (ModelState.IsValid)
            {
                participantToAdd.Id                   = (Guid.NewGuid()).ToString();
                participantToAdd.CreateTime           = DateTime.Now;
                participantToAdd.Subject              = participant.Subject;
                participantToAdd.StatusId             = 1;
                participantToAdd.Description          = participant.Description;
                participantToAdd.UserId               = HttpContext.User.Identity.Name;
                participantToAdd.CompetitionSubjectId = participant.CompetitionSubjectId;

                if (formCollection.Files != null)
                {
                    foreach (var file in formCollection.Files)
                    {
                        var fileContent = ContentDispositionHeaderValue.Parse(file.ContentDisposition);

                        //var id = HttpContext.User.Identity.Name;
                        // Some browsers send file names with full path.
                        // We are only interested in the file name.
                        var format       = Path.GetExtension(fileContent.FileName.ToString().Trim('"'));
                        var filename     = Guid.NewGuid().ToString() + format;
                        var physicalPath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\uploads\" + HttpContext.User.Identity.Name, filename);
                        var path         = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\uploads\" + HttpContext.User.Identity.Name);

                        bool exists = Directory.Exists(path);

                        if (!exists)
                        {
                            Directory.CreateDirectory(path);
                        }

                        using (var fileStream = new FileStream(physicalPath, FileMode.Create))
                        {
                            await file.CopyToAsync(fileStream);
                        }

                        participantToAdd.AttachedFile = filename;
                    }
                }

                _context.Add(participantToAdd);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(participantToAdd));
        }
Пример #13
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,FullName,PhoneNumber,PhoneNumberConfirmed,Email,EmailConfirmed,PhoneNumberVerifyCode,Role,AccessFailedCount,CreateTime,LastUpdateTime,IsActive")] UserViewModel user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }
            var userToEdit = _context.Users.Find(user.Id);

            userToEdit.FullName             = user.FullName;
            userToEdit.PhoneNumber          = user.PhoneNumber;
            userToEdit.IsActive             = user.IsActive;
            userToEdit.Email                = user.Email;
            userToEdit.PhoneNumberConfirmed = user.PhoneNumberConfirmed;
            userToEdit.EmailConfirmed       = user.EmailConfirmed;
            userToEdit.LastUpdateTime       = DateTime.Now;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userToEdit);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                if (user.Role == "Participant")
                {
                    return(RedirectToAction(nameof(Participants)));
                }
                else if (user.Role == "Expert")
                {
                    return(RedirectToAction(nameof(Experts)));
                }
                else
                {
                    return(RedirectToAction(nameof(Supporters)));
                }
            }
            return(View(user));
        }
Пример #14
0
        public async Task <string> DeleteDocumentAsync(DocumentViewModel document)
        {
            var documentToDelete = await _dbContext.Documents.FindAsync(document.Id);

            _dbContext.Documents.Remove(documentToDelete);
            await _dbContext.SaveChangesAsync();

            return("success");
        }
Пример #15
0
        public async Task <IActionResult> PostUser([FromBody] User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Users.Add(user);

            await _context.SaveChangesAsync();

            var options = new PusherOptions();

            options.Cluster = "ap1";
            var            pusher = new Pusher("649204", "068d00130871386d6b37", "59c57f8ff64c56f95886", options);
            ITriggerResult result = await pusher.TriggerAsync("asp_channel", "asp_event", user);

            return(Content("ok"));
        }
Пример #16
0
        public async Task <ActionResult <Person> > Post([FromBody] Person person)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid request object"));
                }
                else
                {
                    await _dbContext.Persons.AddAsync(person);

                    await _dbContext.SaveChangesAsync();

                    return(Created($"https://azwebapiexample20190910011131.azurewebsites.net/api/person/{person.ID}", person));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, $"Person not created. {ex.StackTrace}"));
            }
        }
        public string GetUser(string userId, string avatarUrl)
        {
            var user = (from u in _dbContext.Users
                        where u.Id == Guid.Parse(userId)
                        select u).FirstOrDefault();

            if (user != null)
            {
                user.Avatar = avatarUrl;
                _dbContext.Update(user);
                _dbContext.SaveChangesAsync();
                return("success");
            }
            else
            {
                return("fail");
            }
        }
Пример #18
0
        public async Task <IActionResult> UserContributionEdit(string id, UserContributionEditViewModel participant, IFormCollection formCollection)
        {
            if (id != participant.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var participantToUpdate = await _context.Participants.FindAsync(id);

                    participantToUpdate.LastUpdateTime       = DateTime.Now;
                    participantToUpdate.CompetitionSubjectId = participant.CompetitionSubjectId;
                    participantToUpdate.Description          = participant.Description;
                    participantToUpdate.Subject        = participant.Subject;
                    participantToUpdate.StatusId       = participant.StatusId;
                    participantToUpdate.LastStatusTime = DateTime.Now;

                    if (formCollection.Files != null)
                    {
                        foreach (var file in formCollection.Files)
                        {
                            var fileContent = ContentDispositionHeaderValue.Parse(file.ContentDisposition);

                            var userId = HttpContext.User.Identity.Name;
                            // Some browsers send file names with full path.
                            // We are only interested in the file name.
                            var format       = Path.GetExtension(fileContent.FileName.ToString().Trim('"'));
                            var filename     = Guid.NewGuid().ToString() + format;
                            var physicalPath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\uploads\" + userId, filename);
                            var path         = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\uploads\" + userId);

                            bool exists = Directory.Exists(path);

                            if (!exists)
                            {
                                Directory.CreateDirectory(path);
                            }

                            // The files are not actually saved in this demo
                            using (var fileStream = new FileStream(physicalPath, FileMode.Create))
                            {
                                await file.CopyToAsync(fileStream);
                            }

                            participantToUpdate.AttachedFile = filename;
                        }
                    }
                    _context.Update(participantToUpdate);
                    await _context.SaveChangesAsync();

                    var userPhoneNumber = (from u in _userManager.Users
                                           where u.Id == participantToUpdate.UserId
                                           select u.PhoneNumber).FirstOrDefault();
                    var statusTitle = (from s in _context.Statues
                                       where s.StatusId == participant.StatusId
                                       select s.Title).FirstOrDefault();
                    Classes.SendSmsAsync(userPhoneNumber, "مشارکت", statusTitle, "changestatus");
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ParticipantExists(participant.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                var url = "/ParticipantUsers/UserContributions/" + participant.UserId;
                return(Redirect(url));
            }

            return(View(participant));
        }
Пример #19
0
        private async Task <Document> InsertDocument(documento new_documento)
        {
            using (var transaction = _dbContext.Database.CurrentTransaction ?? _dbContext.Database.BeginTransaction())
            {
                try
                {
                    int last_id = _dbContext.documento.Max(doc => doc.id_interno);
                    new_documento.id_interno = last_id + 1;
                    _dbContext.documento.Add(new_documento);
                    await _dbContext.SaveChangesAsync();

                    // Insert a row
                    OrdenesCompra purcharseOrder = _dbContext.ordenes_compra.
                                                   Where(po => po.id_orden_compra == new_documento.id_orden_compra &&
                                                         po.ruc_empresa_cliente == new_documento.ruc_empresa_cliente).
                                                   FirstOrDefault();

                    //throw new Exception();

                    if ((purcharseOrder != null) ? !purcharseOrder.id_orden_compra.Equals("--") : false)
                    {
                        var empresa = _dbContext.empresas.FirstOrDefault(ent => ent.ruc_empresa.Equals(purcharseOrder.ruc_empresa_cliente));
                        purcharseOrder = Tolerance.ToleranceCalculate(purcharseOrder, empresa, new_documento);
                        await _dbContext.SaveChangesAsync();
                    }

                    transaction.Commit();
                    return(_mapper.Map <Document>(new_documento));
                }
                catch (Exception err)
                {
                    transaction.Rollback();
                    throw err;
                }
                finally
                {
                    transaction.Dispose();
                }
            }

            //OrdenesCompra purcharseOrder = _dbContext.ordenes_compra.
            //    Where(po => po.id_orden_compra == new_documento.id_orden_compra &&
            //        po.ruc_empresa_cliente == new_documento.ruc_empresa_cliente).
            //    FirstOrDefault();

            /*PurcharseOrder pox = _mapper.Map<PurcharseOrder>(purcharseOrder);
             * OrdenesCompra purcharseOrdernew = _mapper.Map<OrdenesCompra>(pox);*/
            //var purcharseOrdernew = new OrdenesCompra();

            /*if ((purcharseOrder != null) ? !purcharseOrder.id_orden_compra.Equals("--") : false)
             * {
             *  var empresa = _dbContext.empresas.FirstOrDefault(ent => ent.ruc_empresa.Equals(purcharseOrder.ruc_empresa_cliente));
             *
             *  purcharseOrdernew.monto_acumulado = 455879;
             *  var tenp = "klkss";
             *  //purcharseOrdernew = Tolerance.ToleranceCalculate(purcharseOrder, empresa, new_documento);
             *  var temp = AuditoriaHelper.OrdenDeCompraAuditorias(purcharseOrder, purcharseOrdernew);
             * }*/

            /*
             * using (var context = _dbContext)
             * {
             *  using (var transaction = _dbContext.Database.BeginTransaction())
             *  {
             *      try
             *      {
             *          //documento nuevo
             *          _dbContext.documento.Add(new_documento);
             *
             *          await _dbContext.SaveChangesAsync();
             *
             *          OrdenesCompra purcharseOrder = _dbContext.ordenes_compra.
             *              Where(po => po.id_orden_compra == new_documento.id_orden_compra &&
             *                  po.ruc_empresa_cliente == new_documento.ruc_empresa_cliente).
             *              FirstOrDefault();
             *
             *          if ((purcharseOrder != null) ? !purcharseOrder.id_orden_compra.Equals("--") : false)
             *          {
             *              var empresa = _dbContext.empresas.FirstOrDefault(ent => ent.ruc_empresa.Equals(purcharseOrder.ruc_empresa_cliente));
             *              purcharseOrder = Tolerance.ToleranceCalculate(purcharseOrder, empresa, new_documento);
             *              await _dbContext.SaveChangesAsync();
             *          }
             *
             *          var document = _mapper.Map<documento>(new_documento);
             *
             *
             *          transaction.Commit();
             *      }
             *      catch (Exception err)
             *      {
             *          transaction.Rollback();
             *          throw err;
             *      }
             *      finally
             *      {
             *          transaction.Dispose();
             *          context.Dispose();
             *          //transaction.Commit();
             *      }
             *  }
             * }*/
        }